public class Solution {
    public static void main(String[] args) {

    }
    //长度最小的子数组
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int n = nums.length;
        int ret = Integer.MAX_VALUE;
        int sum = 0;
        while(right < n)  {
            //进窗口
            if(sum < target) {
                sum += nums[right];
            }
            while(sum >= target) {
                ret = Math.min(ret, right - left + 1);
                sum -= nums[left];
                left++;
            }
            right++;

        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }

}
